<?php

require_once __DIR__ . '/../../config.php';

/**
 * \BF\Config\Value test case.
 *
 * @since v1.0.0
 */
class ValueTest extends \PHPUnit_Framework_TestCase
{

   # <editor-fold defaultstate="collapsed" desc=" - - -   P R I V A T E   F I E L D S   - - - - - - - - - - - - - - - - - - - - - -">

   private $vals;

   # </editor-fold>

   public function setUp()
   {

      $this->vals = array();

      #                                     $name,       $value,                            $isStrict, $typeName
      $this->vals[] = new \BF\Config\Value( 'Boolean1',  true,                              false,     null );       #0
      $this->vals[] = new \BF\Config\Value( 'Boolean2',  false,                             true,      null );       #1
      $this->vals[] = new \BF\Config\Value( 'Boolean3',  false,                             true,      'boolean' );  #2
      $this->vals[] = new \BF\Config\Value( 'Boolean4',  '1',                               true,      'boolean' );  #3
      $this->vals[] = new \BF\Config\Value( 'Boolean5',  null,                              true,      'boolean' );  #4
      $this->vals[] = new \BF\Config\Value( 'Integer1',  -10,                               false,     null );       #5
      $this->vals[] = new \BF\Config\Value( 'Integer2',  0,                                 true,      null );       #6
      $this->vals[] = new \BF\Config\Value( 'Double1',   -1.02,                             false,     null );       #7
      $this->vals[] = new \BF\Config\Value( 'Double2',   0.01,                              true,      null );       #8
      $this->vals[] = new \BF\Config\Value( 'String1',   '-1.02',                           false,     null );       #9
      $this->vals[] = new \BF\Config\Value( 'String2',   "",                                true,      null );       #10
      $this->vals[] = new \BF\Config\Value( 'Array1',    array(),                           false,     null );       #11
      $this->vals[] = new \BF\Config\Value( 'Array2',    array(1),                          true,      null );       #12

   }

   public function testValue0()
   {
      $i = 0;
      $this->assertFalse ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertFalse ( $this->vals[ $i ]->isStrictlyTyped(), "Test {$i}-isStrictlyTyped() fails" );
      $this->assertEquals( 'Boolean1', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'Boolean1', $this->vals[ $i ]->getName(), "Test {$i}-getName() fails" );
      $this->assertEquals( 'bool',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( 'bool',  $this->vals[ $i ]->getType(), "Test {$i}-getType() fails" );
      $this->assertTrue  ( $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertTrue  ( $this->vals[ $i ]->getValue(), "Test {$i}-getValue() fails" );
      $this->assertEquals(
         array(
            'value'    => true,
            'type'     => 'bool',
            'isstrict' => false,
            'name'     => 'Boolean1'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => true,
            'type'     => 'bool',
            'isstrict' => false,
            'name'     => 'Boolean1'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
      $this->vals[ $i ]->Value = 1;
      $this->assertEquals( 'int',  $this->vals[ $i ]->Type, "Test {$i}-Type fails after change to integer value" );
      $this->vals[ $i ]->setValue( 'a string' );
      $this->assertEquals( 'string',  $this->vals[ $i ]->Type, "Test {$i}-Type fails after change to string value" );
      $serialized = serialize( $this->vals[ $i ] );
      $this->assertEquals(
         'C:15:"BF\Config\Value":102:{a:4:{s:5:"value";s:8:"a string";s:4:"type";s:6:"string";s:8:"isstrict";b:0;s:4:"name";s:8:"Boolean1";}}',
         $serialized, "Test {$i}-serialize() fails" );
      $this->vals[ $i ] = unserialize( $serialized );
      $this->assertFalse ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails after deserializing" );
      $this->assertEquals( 'Boolean1', $this->vals[ $i ]->Name, "Test {$i}-Name fails after deserializing" );
      $this->assertEquals( 'string',  $this->vals[ $i ]->Type, "Test {$i}-Type fails after deserializing" );
      $this->assertEquals( 'a string', $this->vals[ $i ]->Value, "Test {$i}-Value fails after deserializing" );
   }

   public function testValue1()
   {
      $i = 1;
      $this->assertTrue  ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertTrue  ( $this->vals[ $i ]->isStrictlyTyped(), "Test {$i}-isStrictlyTyped() fails" );
      $this->assertEquals( 'Boolean2', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'Boolean2', $this->vals[ $i ]->getName(), "Test {$i}-getName() fails" );
      $this->assertEquals( 'bool',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( 'bool',  $this->vals[ $i ]->getType(), "Test {$i}-getType() fails" );
      $this->assertFalse ( $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertFalse ( $this->vals[ $i ]->getValue(), "Test {$i}-getValue() fails" );
      $this->assertEquals(
         array(
            'value'    => false,
            'type'     => 'bool',
            'isstrict' => true,
            'name'     => 'Boolean2'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => false,
            'type'     => 'bool',
            'isstrict' => true,
            'name'     => 'Boolean2'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue2()
   {
      $i = 2;
      $this->assertTrue  ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertTrue  ( $this->vals[ $i ]->isStrictlyTyped(), "Test {$i}-isStrictlyTyped() fails" );
      $this->assertEquals( 'Boolean3', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'Boolean3', $this->vals[ $i ]->getName(), "Test {$i}-getName() fails" );
      $this->assertEquals( 'boolean',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( 'boolean',  $this->vals[ $i ]->getType(), "Test {$i}-getType() fails" );
      $this->assertFalse ( $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertFalse ( $this->vals[ $i ]->getValue(), "Test {$i}-getValue() fails" );
      $this->assertEquals(
         array(
            'value'    => false,
            'type'     => 'boolean',
            'isstrict' => true,
            'name'     => 'Boolean3'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => false,
            'type'     => 'boolean',
            'isstrict' => true,
            'name'     => 'Boolean3'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue3()
   {
      $i = 3;
      $this->assertTrue  ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertTrue  ( $this->vals[ $i ]->isStrictlyTyped(), "Test {$i}-isStrictlyTyped() fails" );
      $this->assertEquals( 'Boolean4', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'Boolean4', $this->vals[ $i ]->getName(), "Test {$i}-getName() fails" );
      $this->assertEquals( 'boolean',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( 'boolean',  $this->vals[ $i ]->getType(), "Test {$i}-getType() fails" );
      $this->assertEquals( '1', $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals( '1', $this->vals[ $i ]->getValue(), "Test {$i}-getValue() fails" );
      $this->assertEquals(
         array(
            'value'    => '1',
            'type'     => 'boolean',
            'isstrict' => true,
            'name'     => 'Boolean4'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => '1',
            'type'     => 'boolean',
            'isstrict' => true,
            'name'     => 'Boolean4'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue4()
   {
      $i = 4;
      $this->assertTrue  ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertTrue  ( $this->vals[ $i ]->isStrictlyTyped(), "Test {$i}-isStrictlyTyped() fails" );
      $this->assertEquals( 'Boolean5', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'Boolean5', $this->vals[ $i ]->getName(), "Test {$i}-getName() fails" );
      $this->assertEquals( 'boolean',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( 'boolean',  $this->vals[ $i ]->getType(), "Test {$i}-getType() fails" );
      $this->assertEquals( null, $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals( null, $this->vals[ $i ]->getValue(), "Test {$i}-getValue() fails" );
      $this->assertEquals(
         array(
            'value'    => null,
            'type'     => 'boolean',
            'isstrict' => true,
            'name'     => 'Boolean5'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => null,
            'type'     => 'boolean',
            'isstrict' => true,
            'name'     => 'Boolean5'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue5()
   {
      $i = 5;
      $this->assertFalse ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertEquals( 'Integer1', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'int',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( -10, $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals(
         array(
            'value'    => -10,
            'type'     => 'int',
            'isstrict' => false,
            'name'     => 'Integer1'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => -10,
            'type'     => 'int',
            'isstrict' => false,
            'name'     => 'Integer1'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue6()
   {
      $i = 6;
      $this->assertTrue  ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertEquals( 'Integer2', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'int',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( 0, $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals(
         array(
            'value'    => 0,
            'type'     => 'int',
            'isstrict' => true,
            'name'     => 'Integer2'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => 0,
            'type'     => 'int',
            'isstrict' => true,
            'name'     => 'Integer2'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue7()
   {
      $i = 7;
      $this->assertFalse ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertEquals( 'Double1', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'double',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( -1.02, $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals(
         array(
            'value'    => -1.02,
            'type'     => 'double',
            'isstrict' => false,
            'name'     => 'Double1'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => -1.02,
            'type'     => 'double',
            'isstrict' => false,
            'name'     => 'Double1'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue8()
   {
      $i = 8;
      $this->assertTrue  ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertEquals( 'Double2', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'double',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( 0.01, $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals(
         array(
            'value'    => 0.01,
            'type'     => 'double',
            'isstrict' => true,
            'name'     => 'Double2'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => 0.01,
            'type'     => 'double',
            'isstrict' => true,
            'name'     => 'Double2'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue9()
   {
      $i = 9;
      $this->assertFalse ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertEquals( 'String1', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'string',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( '-1.02', $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals(
         array(
            'value'    => '-1.02',
            'type'     => 'string',
            'isstrict' => false,
            'name'     => 'String1'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => '-1.02',
            'type'     => 'string',
            'isstrict' => false,
            'name'     => 'String1'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue10()
   {
      $i = 10;
      $this->assertTrue  ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertEquals( 'String2', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'string',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( '', $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals(
         array(
            'value'    => '',
            'type'     => 'string',
            'isstrict' => true,
            'name'     => 'String2'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => '',
            'type'     => 'string',
            'isstrict' => true,
            'name'     => 'String2'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue11()
   {
      $i = 11;
      $this->assertFalse ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertEquals( 'Array1', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'array',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( array(), $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals(
         array(
            'value'    => array(),
            'type'     => 'array',
            'isstrict' => false,
            'name'     => 'Array1'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => array(),
            'type'     => 'array',
            'isstrict' => false,
            'name'     => 'Array1'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

   public function testValue12()
   {
      $i = 12;
      $this->assertTrue  ( $this->vals[ $i ]->IsStrict, "Test {$i}-IsStrict fails" );
      $this->assertEquals( 'Array2', $this->vals[ $i ]->Name, "Test {$i}-Name fails" );
      $this->assertEquals( 'array',  $this->vals[ $i ]->Type, "Test {$i}-Type fails" );
      $this->assertEquals( array(1), $this->vals[ $i ]->Value, "Test {$i}-Value fails" );
      $this->assertEquals(
         array(
            'value'    => array(1),
            'type'     => 'array',
            'isstrict' => true,
            'name'     => 'Array2'
         ),
         $this->vals[ $i ]->toArray(),
         "Test {$i}-toArray() fails"
      );
      $this->assertEquals(
         \serialize( array(
            'value'    => array(1),
            'type'     => 'array',
            'isstrict' => true,
            'name'     => 'Array2'
         ) ),
         (string) $this->vals[ $i ],
         "Test {$i}-__toString() fails"
      );
   }

}

